package cinema.Controller;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;

@SuppressWarnings("serial")
@Named
@ViewScoped
public class LoginController implements Serializable {

    @Inject
    private LoginBean loginBean;

    private String uname;
    private String password;

    @PostConstruct
    public void init() {

    }

    public String logIn() {
        try {
            if (loginBean.logIn(uname, password)) {
                return "adminFilms?faces-redirect=true";
            } else {
                FacesContext.getCurrentInstance().addMessage("UserName",
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "wrong username or password", "wrong username or password"));
                return null;
            }
        } catch (Exception e) {
            return null;
        }

    }

    public String getuname() {
        return uname;
    }

    public void setuname(String uname) {
        this.uname = uname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}